'use strict';

const Service = require('egg').Service;

class LinkClassService extends Service {
    async find() {
        let sql = `SELECT * FROM linkClass`;
        const data = await this.app.mysql.query(sql);
        return {data};
    }

    async save (key){
        for (let index = 0; index < 17; index++) {     
              let sql = `INSERT INTO linkClass (id,\`0\`,\`1\`,\`2\`,\`3\`,\`4\`,\`5\`,\`6\`,\`7\`,\`8\`,\`9\`,\`10\`,\`11\`,\`12\`,\`13\`,\`14\`,\`15\`,\`16\`) VALUES ("${index}","${key[index][0]}","${key[index][1]}","${key[index][2]}","${key[index][3]}","${key[index][4]}","${key[index][5]}","${key[index][6]}","${key[index][7]}","${key[index][8]}","${key[index][9]}","${key[index][10]}","${key[index][11]}","${key[index][12]}","${key[index][13]}","${key[index][14]}","${key[index][15]}","${key[index][16]}")`;
              await this.app.mysql.query(sql);  
        }
    }

    async update(key){
        for (let index = 0; index < 23; index++) {
         let sql = `UPDATE linkClass SET id="${index}" WHERE \`0\`="${key[index][0]}" AND \`1\`="${key[index][1]}" AND \`2\`="${key[index][2]}" AND \`3\`="${key[index][3]}" AND \`4\`="${key[index][4]}" AND \`5\`="${key[index][5]}" AND \`6\`="${key[index][6]}" AND \`7\`="${key[index][7]}" AND \`8\`="${key[index][8]}" AND \`9\`="${key[index][9]}" AND \`10\`="${key[index][10]}" AND \`11\`="${key[index][11]}" AND \`12\`="${key[index][12]}" AND \`13\`="${key[index][13]}" AND \`14\`="${key[index][14]}" AND \`15\`="${key[index][15]}" AND \`16\`="${key[index][16]}" AND \`17\`="${key[index][17]}" AND \`18\`="${key[index][18]}" AND \`19\`="${key[index][19]}" AND \`20\`="${key[index][20]}" AND \`21\`="${key[index][21]}" AND \`22\`="${key[index][22]}"`;
          await this.app.mysql.query(sql);    
        }
    }
    
    
}

module.exports = LinkClassService;
